/*
 * Licensed to the 南京汇海交通科技有限公司
 *
 * Copyright (c) 2025.
 * All rights reserved.
 *
 * 本软件属南京汇海交通科技有限公司所有，在未获得南京汇海交通科技有限公司正式授权情况下，任何企业和个人，不能获取、阅读、安装、传播本软件涉及的任何受知识产权保护的内容。
 */
package com.chframework.cloud.web.reactive;

import com.chframework.cloud.core.openfeign.FeignClientAdvice;
import com.chframework.cloud.web.openfeign.ReactiveFeignClientAdvice;
import com.chframework.cloud.core.properties.FeignHeaderProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.config.WebFluxConfigurer;

@Configuration(proxyBeanMethods = false)
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
@ConditionalOnClass(WebFluxConfigurer.class)
public class FeignReactiveAutoConfig {

    private FeignHeaderProperty feignHeaderProperty;

    @Autowired(required = false)
    public void setFeignHeaderProperty(FeignHeaderProperty feignHeaderProperty) {
        this.feignHeaderProperty = feignHeaderProperty;
    }

    /**
     * Reactive环境下
     * 默认实现FeignClient请求与响应两个阶段的回调
     */
    @Bean
    @ConditionalOnMissingBean
    public FeignClientAdvice reactiveFeignClientAdvice() {
        return new ReactiveFeignClientAdvice(feignHeaderProperty);
    }

}
